package paidaxing.blog.post.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import paidaxing.blog.post.entity.PostTags;
import paidaxing.blog.post.mapper.PostTagsDao;
import paidaxing.blog.post.service.PostTagsService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;


/**
 * 文章标签关联服务实现类
 */
@Service("postTagsService")
public class PostTagsServiceImpl implements PostTagsService {
    @Autowired
    private PostTagsDao postTagsDao;

    @Override
    public PostTags queryById(Long id) {
        return this.postTagsDao.queryById(id);
    }

    @Override
    public Page<PostTags> queryByPage(PostTags postTags, PageRequest pageRequest) {
        long total = this.postTagsDao.count(postTags);
        return new PageImpl<>(this.postTagsDao.queryAllByLimit(postTags, pageRequest), pageRequest, total);
    }

    @Override
    public PostTags insert(PostTags postTags) {
        this.postTagsDao.insert(postTags);
        return postTags;
    }

    @Override
    public PostTags update(PostTags postTags) {
        this.postTagsDao.update(postTags);
        return this.queryById(postTags.getId());
    }

    @Override
    public boolean deleteById(Long id) {
        return this.postTagsDao.deleteById(id) > 0;
    }
}
